package com.itboye.hutouben.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutouben.R;
import com.itboye.hutouben.bean.PayFangShiBean;

import java.util.List;

/**
 * 支付方式
 */
public class PayFangShiAdapter extends BaseAdapter {

    List<PayFangShiBean> list;
    Context context;
    ViewHolder holder=null;
    public PayFangShiAdapter(Context context,List<PayFangShiBean> list){
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if(view==null){
            holder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.item_pay_fangshi,null);
            holder.pay_img= (ImageView) view.findViewById(R.id.pay_img);
            holder.pay_check= (ImageView) view.findViewById(R.id.pay_check);
            holder.pay_name= (TextView) view.findViewById(R.id.pay_name);
            holder.pay_content= (TextView) view.findViewById(R.id.pay_content);
            view.setTag(holder);
        }else{
            holder=(ViewHolder)view.getTag();
        }
        holder.pay_name.setText(list.get(position).getName());
        holder.pay_content.setText(list.get(position).getDesc());

        if(list.get(position).getType().equals("1")){
            holder.pay_img.setBackgroundResource(R.drawable.zhifubao);
            holder.pay_check.setBackgroundResource(R.drawable.pay_type_selected);
        }
        if(list.get(position).getType().equals("2")){
            holder.pay_img.setBackgroundResource(R.drawable.wallet);
        }
        if(list.get(position).getType().equals("3")){
            holder.pay_img.setBackgroundResource(R.drawable.weixin);
        }
        holder.pay_check.setBackgroundResource(R.drawable.pay_type_selected);
        holder.pay_check.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                holder.pay_check.setBackgroundResource(R.drawable.pay_type_selected);
                return false;
            }
        });

        return view;
    }

    class ViewHolder{
        ImageView pay_img,pay_check;
        TextView pay_name,pay_content;
    }
}
